<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ProjectService
 *
 * @author admin
 */
class Service_ProjectService {
    public function __construct()
    {
    }

    /**
     * @return Ahs_VO_Project
     */
    public function getProject()
    {
        $id = 2;
        $projectMapper = new Application_Model_ProjectMapper();
        $project = $projectMapper->fetchById($id);

        $projectVO = $this->_toProjectVO($project);

        return $projectVO;
    }

    /**
     * @return array
     */
    public function getProjects()
    {   
        $projectMapper = new Application_Model_ProjectMapper();
        $projects = $projectMapper->fetchAll();

        $projectVOs = $this->_toProjectVOs($projects);

        return $projectVOs;
    }

    /**
     * @return array
     */
    
    public function getProjectsListByCreatorId($creatorid)
    {
        $projectMapper = new Application_Model_ProjectMapper();
        $projects = $projectMapper->fetchByCreatorId($creatorid);

        $projectVOs = $this->_toProjectVOs($projects);

        return $projectVOs;
        
    }
    
    public function getProjectsFromUserId($userId)
    {
        $projectMapper = new Application_Model_ProjectMapper();
        $projects = $projectMapper->fetchByUserId($userId);

        $projectVOs = $this->_toProjectVOs($projects);

        return $projectVOs;
    }
    
    public function getUsersFromProjectId($projectId)
    {
        $projectMapper = new Application_Model_ProjectMapper();
        $users = $projectMapper->fetchUsersFromProjectId($projectId);

        return $users;
        ///$test = "test";
        //return $test;
    }

    /**
     * @param Application_Model_Project $project
     * @return VO_Project
     */
    private function _toProjectVO(Application_Model_Project $project)
    {
        $projectVO = new VO_Project();
        $projectVO->id              = $project->Id;
        $projectVO->name            = $project->Name;
        $projectVO->description     = $project->Description;
        $projectVO->onhold          = $project->Onhold;
        $projectVO->deleted         = $project->Deleted;
        $projectVO->starttime       = $project->Starttime;
        $projectVO->endtime         = $project->Endtime;
        $projectVO->creationdate    = $project->Creationdate;
        $projectVO->creator         = $project->Creator;
        
        return $projectVO;
    }

    /**
     * @param array $projects
     * @return array
     */
    private function _toProjectVOs($projects = array())
    {
        $projectVOs = array();
        foreach ($projects as $project) {
            $projectVOs[] = $this->_toProjectVO($project);
        }

        return $projectVOs;
    }
    
    public function logOut()
    {
        Zend_Auth::getInstance()->clearIdentity();
    }
}

?>
